<template>
  <div class="dialog" v-show="showMask">
    <div class="dialog-container">
      <div class="btns">
        <div class="title">设备名称</div>
        <input v-focus class="input" type="text" v-model="name" />
        <div class="divider"></div>
        <div class="cancelContainer">
          <div class="confirm" @click="clickConfirm">{{ confirmText }}</div>
          <div class="divider"></div>
          <div class="cancel" @click="clickCancel">{{ cancelText }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    value: false,
    oldName: {
      type: String,
      default: "九牧智能设备",
    },
    cancelText: {
      type: String,
      default: "取消",
    },
    confirmText: {
      type: String,
      default: "确定",
    },
    bottom: {
      type: Number,
      default: 405,
    },
  },
  data() {
    return {
      showMask: false,
      name: "",
    };
  },
  mounted() {
    this.name = this.oldName;
    this.showMask = this.value;
  },
  computed: {},
  methods: {
    closeMask() {
      this.showMask = false;
    },
    clickConfirm() {
      this.$emit("confirm", this.name);
      this.closeMask();
    },
    clickCancel() {
      this.$emit("cancel");
      this.closeMask();
    },
  },

  watch: {
    // oldName(newVal, oldVal) {
    //   this.name = newVal;
    // },
    value(newVal, oldVal) {
      console.log("value = ", newVal);
      this.showMask = newVal;
    },
    showMask(val) {
      this.$emit("input", val);
    },
  },

  //输入框自动获取焦点（需要在<input>标签中添加v-focus)
  directives: {
    focus: function (el) {
      el.focus();
    },
  },
};
</script>
<style lang="less" scoped>
.dialog {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9999;
  .dialog-container {
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    // .btnsShow {
    //   transform: translateY(0%);
    // }
    .btns {
      border-radius: 16px;
      box-shadow: 0px 8px 18px rgba(0, 0, 0, 0.25);
      width: 100%-6px;
      height: 200px;
      display: flex;
      flex-direction: column;
      margin-bottom: 10px;
      background: rgba(255, 255, 255, 1);
      // transition: all 0.3s ease;
      // transform: translateY(20%);
      .title {
        font-size: 20px;
        color: rgba(0, 0, 0, 1);
        margin-top: 25px;
        margin-left: 24px;
        margin-bottom: 28px;
      }
      .input {
        margin-left: 24px;
        margin-right: 24px;
        font-size: 16px;
        color: #000000;
        outline-color: invert;
        outline-style: none;
        outline-width: 0px;
        border: none;
        border-style: none;
        text-shadow: none;
        font-size: 16px;
        -webkit-appearance: none;
        -webkit-user-select: text;
        outline-color: transparent;
        box-shadow: none;
      }
      .divider {
        height: 1px;
        margin-left: 24px;
        margin-right: 24px;
        margin-top: 13px;
        background: rgba(0, 0, 0, 0.2);
      }

      .cancelContainer {
        margin-top: 6px;
        height: 72px;
        margin-left: 24px;
        margin-right: 24px;

        display: flex;
        flex-direction: row;
        justify-content: space-evenly;
        align-items: center;
        .cancel {
          font-size: 16px;
          color: #0a59f7;
        }
        .confirm {
          font-size: 16px;
          color: #0a59f7;
        }
        .divider {
          height: 24px;
          width: 1px;
          background: rgba(0, 0, 0, 0.2);
        }
      }
    }
  }
}
</style>
